<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<jsp:include page="/jsp/common.jsp" />
<jsp:include page="/jsp/formHead.jsp" />
<jsp:include page="/jsp/listHead.jsp" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>resource/css/user.css" />
<script type="text/javascript">
$().ready(function(){

	var districtBox = QDistrictBox.init("#districtPick");
	districtBox.refresh(QDistrictBox.option.data);

	var address = "${entity.address }";
	if(address){

		districtBox.setValue(address);
		$("input[name='addressDetail']").val(address.split(";")[3]);
	}

	$(".updateForm").submit(function(){

		var disctrict = districtBox.getValue(),
			disctrictDetail = $("input[name='addressDetail']").val();
		
		$("input[name='address']").val(disctrict == -1 ? disctrictDetail : disctrict + ";" + disctrictDetail);
	});
	
	$(".updateForm").validate({
		rules: {
			contact : {
				required: true,
				pattern : /^[0-9a-z_A-Z\u4e00-\u9fa5]+$/,
				minlength: 2,
				maxlength: 16
			},
			address : {
				required: true,
				isDistrict : true
			},
			addressDetail: {
				required: true,
				pattern : /^[0-9a-z_A-Z\u4e00-\u9fa5]+$/
			},
			postcode : {
				isPostcode : true
			},
			tel: {
				required: true,
				isPhone: true
			}
		},
		messages: {
			address: {
				pattern: "非法字符",
				remote: "用户名被禁用或已存在"
			}
		}
	});
});
</script>
</head>
<body>
<jsp:include page="../header.jsp" />
<div class="content">
<div class="bar">
	<jsp:include page="./menu.jsp" />
	<div class="list_div_01 border_radius_3">
		<div class="list_title">收货地址</div>
		<form action="<%=basePath %>user/receiver_save.do" method="post" class="updateForm">
			<table>
				<tr>
					<th><span class="requiredField">*</span>收货人:</th>
					<td><input name="contact" type="text" class="text" maxlength="200" value="${entity.contact }"/></td>
				</tr>
				<tr>
					<th><span class="requiredField">*</span>地区:</th>
					<td>
						<div id="districtPick"></div>
						<input name="id" type="hidden" value="${entity.id }" />
						<input name="address" type="hidden" />
					</td>
				</tr>
				<tr>
					<th><span class="requiredField">*</span>地址:</th>
					<td><input name="addressDetail" type="text" class="text" maxlength="200" /></td>
				</tr>
				<tr>
					<th>邮编:</th>
					<td><input name="postcode" type="text" class="text" maxlength="200" value="${entity.postcode }"/></td>
				</tr>
				<tr>
					<th><span class="requiredField">*</span>联系电话:</th>
					<td><input name="tel" type="text" class="text" maxlength="200" value="${entity.tel }"/></td>
				</tr>
				<tr>
					<th>是否默认:</th>
					<td><input type="checkbox" name="is_default"/></td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td>
						<input type="submit" class="submit" value="提交" />
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>
</div>
<jsp:include page="../footer.jsp" />
</body>
</html>